package com.gate.way.demo.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

/**
 * @author wangzhilong
 * @date 2021/3/18
 */
@Component
@Order(1)
public class AuthFilter implements WebFilter {

    private final Logger log = LoggerFactory.getLogger(getClass());


    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        log.info("AuthFilter 执行");
        exchange.getAttributes().put("name", "wzl");
        //exchange.getRequest 获取的是只读请求 如果涉及到修改需要使用 mutate 方法获取一个新的变体请求
        exchange.getRequest().mutate().header("token","111");
        return chain.filter(exchange);
    }
}
